//
//  DataService.m
//  WeatherOFChangsha
//
//  Created by zkingsoft on 15/12/10.
//  Copyright (c) 2015年 zkingsoft. All rights reserved.
//

#import "DataService.h"

#import "AFNetworking.h"

@implementation DataService

+ (AFHTTPRequestOperation *)requestURL:(NSString *)urlString
                            httpMethod:(NSString *)method
                                params:(NSDictionary *)params
                            completion:(void(^)(id result))block {
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation = nil;
    
    // GET请求
    if ([method isEqualToString:@"GET"]) {
        
        operation = [manager GET:urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            //            NSLog(@"====%@", operation.responseString);
            // 回调block
            if (block != nil) {
                block(responseObject);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
            // 错误提示
            NSLog(@"网络请求失败：%@",error);
        }];
    }
    // POST请求
    else if ([method isEqualToString:@"POST"]){
        // 无图片，音频、视频
        operation = [manager POST: urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            // 回调block
            if (block != nil) {
                block(responseObject);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"网络请求失败：%@",error);
        }];
    }
    
    return operation;
}


@end
